import React, { Component } from 'react';
// import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { enterPage } from 'utils/track';
import { Section } from '@alife/devops-ui';
import * as actions from '../actions/index';
import DefaultBranchForm from './defaultBranchForm';
import ProtectedBranchesForm from './protectedBranchesForm';
import intl from '../../../../../../../../../locale';

const { pathResource } = window.FORCE;

class Root extends Component {
  componentDidMount() {
    const fullName = pathResource.fullName.split('/')[1]
      ? pathResource.fullName.split('/')[1].trim()
      : '';
    document.title = intl.get(
      {
        id: 'code-assets.settingsBranches.containers.root.BranchSettingsFullnameCloudEffect',
        defaultMessage: '分支设置 · {fullName} · 云效 Codeup',
      },
      { fullName },
    );
    this.props.getBaseFormInfo();
    this.props.getProtectedBranches();
    this.props.getFlowBuildNames();

    enterPage('Repo-Settings-Branches');
  }

  updateDefaultValue = (defaultBranch) => {
    this.props.updateData({
      defaultBranch,
    });
  };

  render() {
    return (
      <>
        <Section
          title={intl.get({
            id: 'code-assets.settingsBranches.containers.defaultBranchForm.DefaultBranch',
            defaultMessage: '默认分支',
          })}
          description={intl.get({
            id: 'code-assets.settingsBranches.containers.defaultBranchForm.TheDefaultBranchIsConsidered',
            defaultMessage:
              '默认分支被视为代码库中的基本分支，是所有 clone、代码提交和合并请求的目标分支',
          })}
        >
          <DefaultBranchForm {...this.props} />
        </Section>
        <ProtectedBranchesForm {...this.props} />
      </>
    );
  }
}

export default connect(
  (state) => state.project.projectSettings.settingsBranches,
  (dispatch) => bindActionCreators(actions, dispatch),
)(Root);
